<?php
/*
 * [field_builder id='FieldBuilder' label='field' usercap='edit_plugins' tableclasses='table-bordered,table-striped,table-hover,table-condensed']
 *
 */

namespace WebApper\Shortcode;

class FieldBuilder extends \WebApper\Shortcode {
	
    /**
     * Define shortcode properties
     *
     */
	protected $shortcode = 'field_builder';
	protected $defaults = array(
		'id' => null,			// The unique ID to use for the shortcode. Default: none. Required.
		'usercap' => 'edit_plugins',	// The minimum user capability required to access the Field Builder. OPTIONS: 'logged_out', 'read', 'edit_posts', 'edit_others_posts', 'edit_users', 'edit_pages', 'edit_plugins'. Default 'edit_plugins'.
		'label' => 'Field',				// The field label to display. Default: 'Field'.
		'tableclasses' => 'table-bordered,table-striped,table-hover,table-condensed',  // Adjust how the DataTable will display. Default: 'table-bordered,table-striped,table-hover,table-condensed'.
	);

    /**
     * Handles the add post shortcode
     *
     * @param array $atts
     */
    public function shortcode( $atts ) {

		// Get shortcode attributes
			extract( shortcode_atts( $this->defaults, $atts ) );

		// Ouput datatable HTML & Javascript
			?>
            <hr />
            <div class="alert alert-info fade in">
                <button type="button" class="close" data-dismiss="alert">&times;</button>
                <strong>How To!</strong> Use this tool to create fields to use in shortcodes. Records(or posts) are created and managed with shortcodes. Shortcodes must have fields included to create and edit posts with. Rows are selectable. Click on the add, edit, or delete button to get started.
            </div>
			<table id="<?php echo $id; ?>_datatable" class="table <?php echo str_replace(",", " ", $tableclasses); ?>">
				<thead>
					<tr>
						<th>ID</th>
						<th>Label</th>
						<th>Field ID</th>
						<th>Type</th>
						<th>Required</th>
						<th>Fieldset</th>
						<th></th><!-- New Fieldset -->
						<th>Placeholder</th>
						<th>Short description</th>
						<th>Long description</th>
						<th>Options</th>
						<th>Default value</th>
						<th>Validation</th>
						<th>RegExp pattern</th>
						<th>Error message</th>
						<th>Read only</th>
						<th>Show in table</th>
						<th>Order</th>
					</tr>
				</thead>
				<tbody>
					<?php
					global $wpdb;
					$fieldsTable = $wpdb->prefix . 'web_apper_fields';
					$web_apper_fields = $wpdb->get_results(
						'SELECT * FROM ' . $fieldsTable,
						'ARRAY_A'
					);
					foreach ( $web_apper_fields as $field ) :
						echo '<tr>',
								 '<td>', $field['ID'], '</td>',
								 '<td>', stripslashes($field['field_name']), '</td>',
								 '<td>', $field['field_id'], '</td>',
								 '<td>', $field['type'], '</td>',
								 '<td>', $this->boolToText($field['required']), '</td>',
								 '<td>', $field['fieldset'], '</td>',
								 '<td></td><!-- New Fieldset -->',
								 '<td>', stripslashes($field['placeholder']), '</td>',
								 '<td>', stripslashes($field['short_desc']), '</td>',
								 '<td>', stripslashes($field['long_desc']), '</td>',
								 '<td>', stripslashes($field['options']), '</td>',
								 '<td>', stripslashes($field['default_value']), '</td>',
								 '<td>', $field['validation'], '</td>',
								 '<td>', $field['regex'], '</td>',
								 '<td>', stripslashes($field['error_message']), '</td>',
								 '<td>', $this->boolToText($field['read_only']), '</td>',
								 '<td>', $this->boolToText($field['show_in_table']), '</td>',
								 '<td>', $field['field_order'], '</td>',
							 '</tr>';
					endforeach;
					?>
				</tbody>
			</table>
			<script type="text/javascript">
				// Store Commonly manipulated DOM nodes as objects
				nForm = jQuery('#<?php echo $id; ?>');
				nFormTask = jQuery('input[name="task"]', nForm);
				nFieldset = jQuery('select[name="fieldset"]', nForm);
				nNewFieldset = jQuery('input[name="new-fieldset"]', nForm);
				nType = jQuery('select[name="type"]', nForm);
				nRequired = jQuery('input[name="required"]', nForm);
				nPlaceholder = jQuery('input[name="placeholder"]', nForm);
				nShortDesc = jQuery('input[name="short_desc"]', nForm);
				nLongDesc = jQuery('textarea[name="long_desc"]', nForm);
				nOptions = jQuery('textarea[name="options"]', nForm);
				nDefaultValue = jQuery('input[name="default_value"]', nForm);
				nValidation = jQuery('select[name="validation"]', nForm);
				nErrorMessage = jQuery('input[name="error_message"]', nForm);
				nValidation = jQuery('select[name="validation"]', nForm);
				nRegex = jQuery('input[name="regex"]', nForm);
				nReadOnly = jQuery('input[name="read_only"]', nForm);
				nModal = jQuery('.modal', nForm);
				nModalHeader = jQuery('.modal-header h3', nModal)
				nModalBody = jQuery('.modal-body', nModal);
				nModalClose = jQuery('.modal-footer [data-dismiss="modal"]', nModal)
				nModalSaveBtn = jQuery('.modal-footer #save', nModal)
				nModalUpdateBtn = jQuery('.modal-footer #update', nModal)
				nModalDeleteBtn = jQuery('.modal-footer #delete', nModal)
				nModalElements = jQuery('.modal-body>*', nModal);
				nDeleteWarning = jQuery('#deleteWarning', nModal);
				nTable = jQuery('#<?php echo $id; ?>_datatable');
				
				jQuery(document).ready(function($) {
					// Initialize dataTable
					oTable = $(nTable).dataTable({
						<?php
							// Build the sDom parameter for dataTables
							global $template;
							if ( stristr($template, 'fullwidth') ) :
								$spanA = 6; $spanB = 6;
							else :
								$spanA = 4; $spanB = 5;
							endif;
							echo "'sDom': \"<'row'<'span".$spanA."'EC><'span".$spanB."'fl>r>t<'row'<'span".$spanA."'i><'span".$spanB."'p>>\",\n";
						?>
						'sPaginationType': 'bootstrap',
						'oLanguage': {
							'sLengthMenu': 'records per page <select>'+
							'<option value="10">10</option>'+
							'<option value="20">20</option>'+
							'<option value="30">30</option>'+
							'<option value="40">40</option>'+
							'<option value="50">50</option>'+
							'<option value="100">100</option>'+
							'</select>'
						},
						'aoColumnDefs': [ { 'bVisible': false, 'aTargets': [ 0, 6, 7, 8, 9, 10, 11, 12, 13, 14 ] } ],
						"aaSorting": [ [5,'asc'], [17,'asc'] ],
						'oColVis': {
							'buttonText': 'Columns',
							'bRestore': true,
							'sAlign': 'left',
							'sSize': 'css',
							'aiExclude': [ 0, 6 ]
						},
					});
					// Add a click handler for the Editor 'Add' row button
					$('#add_field_builder').on("click", function() {
						nNewFieldset.val('').removeAttr('required').attr('disabled', '');  // Disable New Fieldset input
						nRegex.val('').removeAttr('required').attr('disabled', '');  // Disable Regex input
					});
					// Add a click handler for the Editor 'Edit' row button
					$('#edit_field_builder').on("click", function() {
						nNewFieldset.val('').removeAttr('required').attr('disabled', '');  // Disable New Fieldset input
						if ( nValidation.val() == 'RegExp' )  // Possibly disable Regex input
							nRegex.removeAttr('disabled').attr('required', '');
						else
							nRegex.val('').removeAttr('required').attr('disabled', '');
					});
					// Add jQuery to enable fields depending on the selected 'Type' option
					nType.change(function() {
						checkTypeFields();
					});
					function checkTypeFields() {
						sVal = nType.val();
						if ( sVal == 'Hidden' || sVal == 'HTML' || sVal == 'Legend' ) {
							// Disable all but default value
							nRequired.val(['No']).removeAttr('required').attr('disabled', '');
							nPlaceholder.val('').attr('disabled', '');
							nShortDesc.val('').attr('disabled', '');
							nLongDesc.val('').attr('disabled', '');
							nOptions.val('').attr('disabled', '');
							nDefaultValue.removeAttr('disabled');
							nValidation.val('').attr('disabled', '');
							nErrorMessage.val('').attr('disabled', '');
							nReadOnly.val(['No']).removeAttr('required').attr('disabled', '');
						} else if ( sVal == 'Textbox' || sVal == 'Password' || sVal == 'Textarea' || sVal == 'Phone' || sVal == 'Search' || sVal == 'Url' || sVal == 'Email' ) {
							// Enable all but options
							nRequired.attr('required', '').removeAttr('disabled');
							nPlaceholder.removeAttr('disabled');
							nShortDesc.removeAttr('disabled');
							nLongDesc.removeAttr('disabled');
							nOptions.val('').attr('disabled', '');
							nDefaultValue.removeAttr('disabled');
							nValidation.removeAttr('disabled');
							nErrorMessage.removeAttr('disabled');
							nReadOnly.attr('required', '').removeAttr('disabled');
						} else if ( sVal == 'File' ) {
							nRequired.removeAttr('disabled');
							nPlaceholder.val('').attr('disabled', '');
							nShortDesc.removeAttr('disabled');
							nLongDesc.removeAttr('disabled');
							nOptions.val('').attr('disabled', '');
							nDefaultValue.val('').attr('disabled', '');
							nValidation.val('').attr('disabled', '');
							nErrorMessage.removeAttr('disabled');
							nReadOnly.val(['No']).removeAttr('required').attr('disabled', '');
						} else if ( sVal == 'Select' || sVal == 'Radio' || sVal == 'Checkbox' || sVal == 'Range' || sVal == 'Sort' || sVal == 'Checksort' ) {
							nRequired.val(['No']).removeAttr('required').attr('disabled', '');
							nPlaceholder.val('').attr('disabled', '');
							nShortDesc.val('').attr('disabled', '');
							nLongDesc.val('').attr('disabled', '');
							nOptions.removeAttr('disabled');
							nDefaultValue.val('').attr('disabled', '');
							nValidation.val('').attr('disabled', '');
							nErrorMessage.removeAttr('disabled');
							nReadOnly.attr('required', '').removeAttr('disabled');
						} else if ( sVal == 'Date' || sVal == 'DateTime' || sVal == 'DateTimeLocal' || sVal == 'Month' || sVal == 'Week' || sVal == 'Time' ) {
							nRequired.attr('required', '').removeAttr('disabled');
							nPlaceholder.val('').attr('disabled', '');
							nShortDesc.removeAttr('disabled');
							nLongDesc.removeAttr('disabled');
							nOptions.val('').attr('disabled', '');
							nDefaultValue.val('').attr('disabled', '');
							nValidation.removeAttr('disabled');
							nErrorMessage.removeAttr('disabled');
							nReadOnly.attr('required', '').removeAttr('disabled');
						} else if ( sVal == 'Number' || sVal == 'Color' || sVal == 'jQueryUIDate' ) {
							nRequired.attr('required', '').removeAttr('disabled');
							nPlaceholder.val('').attr('disabled', '');
							nShortDesc.removeAttr('disabled');
							nLongDesc.removeAttr('disabled');
							nOptions.val('').attr('disabled', '');
							nDefaultValue.removeAttr('disabled');
							nValidation.removeAttr('disabled');
							nErrorMessage.removeAttr('disabled');
							nReadOnly.attr('required', '').removeAttr('disabled');
						} else if ( sVal == 'TinyMCE' || sVal == 'CKEditor' ) {
							nRequired.attr('required', '').removeAttr('disabled');
							nPlaceholder.val('').attr('disabled', '');
							nShortDesc.val('').attr('disabled', '');
							nLongDesc.removeAttr('disabled');
							nOptions.val('').attr('disabled', '');
							nDefaultValue.removeAttr('disabled');
							nValidation.removeAttr('disabled');
							nErrorMessage.removeAttr('disabled');
							nReadOnly.attr('required', '').removeAttr('disabled');
						} else if ( sVal == 'State' || sVal == 'Country' || sVal == 'YesNo' ) {
							nRequired.attr('required', '').removeAttr('disabled');
							nPlaceholder.val('').attr('disabled', '');
							nShortDesc.removeAttr('disabled');
							nLongDesc.removeAttr('disabled');
							nOptions.val('').attr('disabled', '');
							nDefaultValue.removeAttr('disabled');
							nValidation.val('').attr('disabled', '');
							nErrorMessage.removeAttr('disabled');
							nReadOnly.attr('required', '').removeAttr('disabled');
						} else if ( sVal == 'Captcha' ) {
							nRequired.val(['No']).removeAttr('required').attr('disabled', '');
							nPlaceholder.val('').attr('disabled', '');
							nShortDesc.val('').attr('disabled', '');
							nLongDesc.val('').attr('disabled', '');
							nOptions.val('').attr('disabled', '');
							nDefaultValue.val('').attr('disabled', '');
							nValidation.val('').attr('disabled', '');
							nErrorMessage.val('').attr('disabled', '');
							nReadOnly.val(['No']).removeAttr('required').attr('disabled', '');
						} else {
							nRequired.attr('required', '').removeAttr('disabled');
							nPlaceholder.removeAttr('disabled');
							nShortDesc.removeAttr('disabled');
							nLongDesc.removeAttr('disabled');
							nOptions.removeAttr('disabled');
							nDefaultValue.removeAttr('disabled');
							nValidation.removeAttr('disabled');
							nErrorMessage.removeAttr('disabled');
							nReadOnly.attr('required', '').removeAttr('disabled');
						}
					};
					// Add jQuery to enable New Fieldset textbox if the option is selected
					nFieldset.change(function() {
						if ( nFieldset.val() == 'new-fieldset' )
							nNewFieldset.removeAttr('disabled').attr('required', '');
						else
							nNewFieldset.val('').removeAttr('required').attr('disabled', '');
					});
					// Add jQuery to enable RegExp textbox if the option is selected
					nValidation.change(function() {
						if ( nValidation.val() == 'RegExp' )
							nRegex.removeAttr('disabled').attr('required', '');
						else
							nRegex.val('').removeAttr('required').attr('disabled', '');
					});

				});
				// Handle response from ajax post
				function parseResponse<?php echo $id; ?>(response) {
					var result = jQuery.parseJSON(response);  // Parse response
					if ( result.success ) {  // If ajax returns a successful save
						if ( result.task == 'save' ) {  // If we added a row
							jQuery('input[name="web_apper_id"]', nForm).val( result.ID );  // Prepend the returned record ID to the array before adding to the dataTable
							var formValues = nForm.getFormValues();  // Get array of form values
							oTable.fnAddDataAndDisplay(formValues);  // Add row to table
							nForm.clearForm();  // Clear form values
						} else if ( result.task == 'update' ) {  // If we updated a row
							var rowPosition = oTable.fnGetPosition( jQuery('tbody tr.row_selected')[0] );  // Get the position of the currently selected row
							var formValues = nForm.getFormValues();  // Get array of form values
							oTable.fnUpdate( formValues, rowPosition ); // Update the dataTable row
						} else if ( result.task == 'delete' ) {  // If we deleted a row
							nDeleteWarning.css('display', 'none');  // Hide the delete warning
							nModalDeleteBtn.css('display', 'none');  // Hide the modal submit button
							var rowPosition = oTable.fnGetPosition( jQuery('tbody tr.row_selected')[0] );  // Get the position of the currently selected row
							oTable.fnDeleteRow( rowPosition );
						}
					}
					resetModalButtons();
					nModalBody.prepend(result.htmlalert);  // Show and alert
				}
			</script>
            <?php

		// Configure form settings
			$this->config_form( $atts );  // Check if user has proper privileges

		// Build the form
			$fieldsetsTable = $wpdb->prefix . 'web_apper_fieldsets';
			$web_apper_fieldsets = $wpdb->get_results(
				'SELECT * FROM ' . $fieldsetsTable,
				'ARRAY_A'
			);
			$fieldsetSelectOptions = array( 'new-fieldset' => 'Create new fieldset' );
			foreach ( $web_apper_fieldsets as $fieldset ) :
				$fieldsetSelectOptions[ $fieldset['fieldset_id'] ] = $fieldset['fieldset_name'];
			endforeach;
			$form = new \PFBC\Form($id);
			$form->configure( $this->formConfig );
			$form->addElement(new \PFBC\Element\Hidden('web_apper_form', $id));
			$form->addElement(new \PFBC\Element\Hidden('web_apper_nonce', wp_create_nonce( 'WebApperAwesomeness!87' )));
			$form->addElement(new \PFBC\Element\Hidden('action', 'web_apper' . $this->shortcode));
			$form->addElement(new \PFBC\Element\Hidden('web_apper_task', 'add'));
			// Form Modal header
			$form->addElement(new \PFBC\Element\ModalHeading($label));
			$form->addElement(new \PFBC\Element\HTML('<div id="deleteWarning"><span class="label label-important pull-left">Delete ' . $label . '</span><p>&nbsp;You are about to delete a ' . $label . '. Are you sure you want to do this?</p></div>'));
			// Form Modal body

			$form->addElement(new \PFBC\Element\Hidden('web_apper_id'));
			$form->addElement(new \PFBC\Element\Textbox('Label:', 'field_name', array(
				"required" => 1,
				'placeholder' => 'Field Label',
				'shortDesc' => 'A readable label for the field'
			)));
			$form->addElement(new \PFBC\Element\Textbox('Field ID:', 'field_id', array(
				"required" => 1,
				'placeholder' => 'field-id',
				'shortDesc' => 'A unique ID for the field',
				'longDesc' => 'Must be alphanumeric: contain only lowercase letters, numbers, underscores(_) and/or hyphens(-).',
				"validation" => new \PFBC\Validation\AlphaNumeric
			)));
			$form->addElement(new \PFBC\Element\Select('Type:', 'type', array(
				'Hidden', 'HTML', 'Legend', 'Textbox', 'Textarea', 'Select', 'Checkbox', 'Radio', 'Email', 'Phone', 'Url', 'jQueryUIDate', 'Date', 'Week', 'Month', 'Number', 'Range', 'Color', 'Checksort', 'Sort', 'CKEditor', 'State', 'Country', 'YesNo', 'Captcha', 'Button'
			)));
			$form->addElement(new \PFBC\Element\YesNo('Required:', 'required', array(
				'longDesc' => 'Make this a required field'
			)));
			$form->addElement(new \PFBC\Element\Select('Fieldset:', 'fieldset', $fieldsetSelectOptions ));
			$form->addElement(new \PFBC\Element\Textbox('New fieldset:', 'new-fieldset', array(
				'shortDesc' => 'Create a new fieldset',
			)));
			$form->addElement(new \PFBC\Element\Textbox('Placeholder:', 'placeholder', array(
				'placeholder' => 'my placeholder',
				'shortDesc' => 'Provides example or hint'
			)));
			$form->addElement(new \PFBC\Element\Textbox('Short description:', 'short_desc', array(
				'shortDesc' => 'This text is a short description'
			)));
			$form->addElement(new \PFBC\Element\Textarea('Long description:', 'long_desc', array(
				'longDesc' => 'This text is a long description.'
			)));
			$form->addElement(new \PFBC\Element\Textarea('Options:', 'options', array(
				'placeholder' => "val-1,Value One | val-2,Value Two",
				'longDesc' => 'Enter option values for fields like checkboxes and radios. Enter options in \'option-value,Option label\' pairs. Use a pipe(|) to seperate pairs.'
			)));
			$form->addElement(new \PFBC\Element\Textbox('Default value:', 'default_value', array(
				'longDesc' => 'A default value to use if one is not saved.'
			)));
			$form->addElement(new \PFBC\Element\Select('Validation:', 'validation', array(
				'', 'AlphaNumeric', 'RegExp'
			)));
			$form->addElement(new \PFBC\Element\Textbox('RegExp pattern:', 'regex', array(
				'disabled' => '',
				'shortDesc' => 'A RegExp to validate against'
			)));
			$form->addElement(new \PFBC\Element\Textbox('Error message:', 'error_message', array(
				'placeholder' => 'The %element% field is missing',
				'longDesc' => 'A custom message to display if the field fails validation.'
			)));
			$form->addElement(new \PFBC\Element\YesNo('Read only:', 'read_only', array(
				'longDesc' => 'A read only field can only be set when a record is added and may not be edited there after.'
			)));
			$form->addElement(new \PFBC\Element\YesNo('Show in tables:', 'show_in_table', array(
				'longDesc' => 'Set the default visibilty of this field\'s column in an [indextable] shortcode.'
			)));
			$form->addElement(new \PFBC\Element\Number('Order:', 'order'));
			// Form Modal footer
			$form->addElement(new \PFBC\Element\Button('Save', 'submit', array(
				'id' => 'save',
				'data-loading-text' => 'Saving...'
			)));
			$form->addElement(new \PFBC\Element\Button('Update', 'submit', array(
				'id' => 'update',
				'data-loading-text' => 'Updating...'
			)));
			$form->addElement(new \PFBC\Element\Button('Delete', 'submit', array(
				'id' => 'delete',
				'class' => 'btn btn-danger',
				'data-loading-text' => 'Deleting...'
			)));
            $form->render();  // Output the form

	}

    /**
     * Add new record
     *
     * @since 1.0
     */
	public function add_record() {
		global $wpdb;
		$wpdb->insert( 
			$wpdb->prefix . 'web_apper_fields',
			array( 
				'field_name' => $_POST['field_name'],
				'field_id' => $_POST['field_id'],
				'type' => $_POST['type'],
				'required' => $this->textToBool($_POST['required']),
				'fieldset' => $_POST['fieldset'],
				'placeholder' => $_POST['placeholder'],
				'short_desc' => $_POST['short_desc'],
				'long_desc' => $_POST['long_desc'],
				'options' => $_POST['options'],
				'default_value' => $_POST['default_value'],
				'validation' => $_POST['validation'],
				'regex' => $_POST['regex'],
				'error_message' => $_POST['error_message'],
				'read_only' => $this->textToBool($_POST['read_only']),
				'show_in_table' => $this->textToBool($_POST['show_in_table']),
				'field_order' => $_POST['order'],
			), 
			array( '%s', '%s', '%s', '%d','%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%d' ) 
		);
		if ( $wpdb->insert_id ) :	
			return $this->sendResponse( 'Field saved.', 'alert-success', 'Hurray!', true, $wpdb->insert_id );  // Send Response
		else :
			return $this->sendResponse( 'There was a problem saving the field. Please Try again.', 'alert-error', 'Oh snap!', false );  // Send Response
		endif;
	}

    /**
     * Update a record
     *
     * @since 1.0
     */
	public function update_record() {
		global $wpdb;
		$result = $wpdb->update(
			$wpdb->prefix . 'web_apper_fields',
			array( 
				'field_name' => $_POST['field_name'],
				'field_id' => $_POST['field_id'],
				'type' => $_POST['type'],
				'required' => $this->textToBool($_POST['required']),
				'fieldset' => $_POST['fieldset'],
				'placeholder' => $_POST['placeholder'],
				'short_desc' => $_POST['short_desc'],
				'long_desc' => $_POST['long_desc'],
				'options' => $_POST['options'],
				'default_value' => $_POST['default_value'],
				'validation' => $_POST['validation'],
				'regex' => $_POST['regex'],
				'error_message' => $_POST['error_message'],
				'read_only' => $this->textToBool($_POST['read_only']),
				'show_in_table' => $this->textToBool($_POST['show_in_table']),
				'field_order' => $_POST['order'],
			), 
			array( 'ID' => $_POST['web_apper_id'] ),
			array( '%s', '%s', '%s', '%d', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%d' )
		);



		// Check for a new fieldset
		if ( $_POST['new-fieldset'] ) {
			$newFieldset = str_replace( array( ' ', '_' ), '-', $_POST['new-fieldset'] );
		}



		if ( $result === 0 ) :	
			return $this->sendResponse( 'The field was not updated because you haven\'t made any changes.', 'alert-info', 'Heads Up!', true );  // Send Response
		elseif ( $result ) :	
			return $this->sendResponse( 'Field updated.', 'alert-success', 'Hurray!', true );  // Send Response
		else :
			return $this->sendResponse( 'There was a problem updating the field. Please Try again.', 'alert-error', 'Oh snap!', false );  // Send Response
		endif;
	}

    /**
     * Delete a record
     *
     * @since 1.0
     */
	public function delete_record() {
		global $wpdb;
		$fieldsTable = $wpdb->prefix . 'web_apper_fields';
		$result = $wpdb->query( $wpdb->prepare( "DELETE FROM $fieldsTable WHERE id = %d", $_POST['web_apper_id'] ) );
		if ( $result ) :	
			return $this->sendResponse( 'Field deleted.', 'alert-success', 'Hurray!', true );  // Send Response
		else :
			return $this->sendResponse( 'There was a problem deleting the field. Please Try again.', 'alert-error', 'Oh snap!', false );  // Send Response
		endif;
	}
	
}

$initialize = new FieldBuilder(); 

?>